package search;

import java.io.File;

public class SearchDemo {
    private static int count = 0;
    public static void main(String[] args) {

        search("E:\\书籍",".java");
        System.out.println(count);

    }


    public static void bianli(String path){
        File dirFile = new File(path);
        if(dirFile.isFile()){
            return;
        }

        File[] files = dirFile.listFiles();
        if(files == null){
            return;
        }
        for(File file:files){
            System.out.println(file.getAbsolutePath());
            count++;
            if(file.isDirectory()){
                //此处需要递归
                bianli(file.getAbsolutePath());
            }
        }

    }


    public static void search(String path,String type){
        File dirFile = new File(path);
        if(dirFile.isFile()){
            return;
        }

        File[] files = dirFile.listFiles();
        if(files == null){
            return;
        }
        for(File file:files){
            if(file.getName().endsWith(type)){
                System.out.println(file.getAbsolutePath());
            }
            //count++;
            if(file.isDirectory()){
                //此处需要递归
                search(file.getAbsolutePath(),type);
            }
        }

    }
}
